; -*- mode: lisp; -*-

;
; this file constructs a simple buggy, the connected agent controlls
; one joint motor
;

(RSG 0 1)
(
 ; install a perceptor to receive the current simulation time
 (nd TimePerceptor)

 ; create the char chassis
 (nd Transform
       (setName chassis)
       (setLocalPos 0 0 0.5)
       (importScene rsg/boxspheres/box.rsg 1 3 0.8 10 matRed)

       (nd Transform
	     (setLocalPos 0 1.3 0.55)
	     (nd Box
		   (setMaterial matBlue)
		   (setExtents 1 0.1 0.3)
		   )
	     )
       )

 ; install the left back tire, this tire is used to accelerate
 (nd Transform
       (setName leftBack)
       (setLocalPos -0.5 -1.5 0)
       (importScene rsg/boxspheres/sphere.rsg 0.4 2 matWhite)
       (nd Transform
	     (setLocalRotation 0 180 0)

	     ; install the joint
	     (nd Hinge2Joint
		   (attach ../../sphereBody ../../../chassis/boxBody)
		   (setAnchor 0 0 0)

		   ; enable the joint motor
		   (setMaxMotorForce 1 4000)

		   ; install a perceptor to measure the tire movement
		   (nd Hinge2Perceptor
			 (setName lb)
			 )

		   ; install an effector to control the joint motor
		   (nd Hinge2Effector)
		   )

	     ; add some boxes to visualize the tire spin
	     (nd Box
		   (setExtents 1 0.1 0.1)
		   (setMaterial matBlue)
		   )

	     (nd Box
		   (setExtents 0.1 1 0.1)
		   (setMaterial matRed)
		   )

	     (nd Box
		   (setExtents 0.1 0.1 1)
		   (setMaterial matYellow)
		   )	     
	     )
       )

 ; install remaining passive wheels

 (nd Transform
       (setName leftFront)
       (setLocalPos -0.5 +1.5 0)
       (importScene rsg/boxspheres/sphere.rsg 0.4 2 matWhite)
       (nd Hinge2Joint
	     (attach ../sphereBody ../../chassis/boxBody)
	     (setAnchor 0 0 0)
	     )
       )

 (nd Transform
       (setName rightBack)
       (setLocalPos 0.5 -1.5 0)
       (importScene rsg/boxspheres/sphere.rsg 0.4 2 matWhite)
       (nd Transform
	     (setLocalRotation 0 180 0)
	     (nd Hinge2Joint
		   (attach ../../sphereBody ../../../chassis/boxBody)
		   (setAnchor 0 0 0)
		   )
	     )
       )

 (nd Transform
       (setName rightFront)
       (setLocalPos 0.5 +1.5 0)
       (importScene rsg/boxspheres/sphere.rsg 0.4 2 matWhite)
       (nd Hinge2Joint
	     (attach ../sphereBody ../../chassis/boxBody)
	     (setAnchor 0 0 0)
	     )
       ) 
)